# -*- coding: utf-8 -*-

"""
DateTime   : 2020/12/12 20:38
Author     : ZhangYafei
Description: 
"""
# 提供过滤条件的函数
def f1(x):
    return x > 50  # 找出大于50的元素

data = [66, 15, 91, 28, 98, 50, 7, 80, 90]
filtered = filter(f1, data)
print(filtered)     # filter object at 0x0000019C57EE92C8>
data2 = list(filtered)   # 转换为列表
print(data2)        # [66, 91, 98, 80, 90]

# 提供变换规则的函数
def f2(x):
    return x * 2  # 变换规则为乘以2

map_res =map(f2, data)
print(map_res)
data3 = list(map_res)
print(data3)




def kfactorial(k):
    """求k的阶乘"""
    if k == 0 or k == 1:
        return 1
    from functools import reduce
    return reduce(lambda x, y: x * y, list(range(1, k + 1)))


def kfactorial2(k):
    a = 1
    for i in range(1, k + 1):
        a *= i
    return a


def kfactorial3(k):
    if k == 0 or k == 1:
        return 1
    else:
        return kfactorial3(k - 1) * k


print(kfactorial(5))
print(kfactorial2(6))
print(kfactorial3(7))